import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

// FeedbackServlet.java 表单处理Servlet
@WebServlet("/ProcessFeedback")
public class FeedbackServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		// 设置中文编码
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");

		// 获取表单参数
		String name = request.getParameter("name");
		String email = request.getParameter("email");
		String feedbackType = request.getParameter("feedbackType");
		String message = request.getParameter("message");

		// 创建反馈对象
		Feedback feedback = new Feedback();
		feedback.setName(name);
		feedback.setEmail(email);
		feedback.setFeedbackType(feedbackType);
		feedback.setMessage(message);

		try {
			DatabaseUtil.saveFeedback(feedback);
			response.sendRedirect("smartfeedback.jsp?status=success");
		} catch (SQLException e) {
			e.printStackTrace();
			response.sendRedirect("smartfeedback.jsp?status=error");
		}
	}
}